package com.carlife.model;

import android.content.ContentValues;
import android.database.Cursor;

import com.carlife.provider.ConditionItem;
import com.carlife.provider.Conditions;
import com.carlife.provider.IModel;

public class OilLog implements IModel{
	
	public static final String TABLENAME = "T_OIL_LOG";
	
	public static final String FD_OIL_NO = "OIL_NO";
	public static final String FD_CAR_NO = "CAR_NO";
	public static final String FD_INPUT_TIME = "INPUT_TIME";
	public static final String FD_UNIT_PRICE = "UNIT_PRICE";
	public static final String FD_OIL_TYPE = "OIL_TYPE";
	public static final String FD_OIL_QUANTITY = "OIL_QUANTITY";
	public static final String FD_OIL_MONEY = "OIL_MONEY";
	
	
	public static final String OIL_TYPE_93 = "93";
	public static final String OIL_TYPE_97 = "97";
	
	
	public static final String [] FIELDS = new String [] {
		FD_OIL_NO,
		FD_CAR_NO,
		FD_INPUT_TIME,
		FD_INPUT_TIME,
		FD_UNIT_PRICE,
		FD_OIL_TYPE,
		FD_OIL_QUANTITY,
		FD_OIL_MONEY
	};
	
	public static final String [] PK_FIELDS = new String [] {
		FD_OIL_NO
	};
	
	private ContentValues maps = new ContentValues(7);
	
	public OilLog() {
		super();
	}
	
	public void put(String key, String value) {
		this.maps.put(key, value);
	}
	
	public Object get(String key) {
		return this.maps.get(key);
	}
	
	@Override
	public ContentValues getContentValues() {
		return this.maps;
	}
	@Override
	public String getModelName() {
		return TABLENAME;
	}
	@Override
	public Conditions getPKCondition() {
		Conditions cond = new Conditions();
		for (int i=0; i<PK_FIELDS.length; i++) {
			ConditionItem item = new ConditionItem(PK_FIELDS[i], maps.get(PK_FIELDS[i]), ConditionItem.EQ);
			cond.addItem(item);
		}
		return cond;
	}
	
	@Override
	public IModel pareseNewModel(Cursor cursor) {
		OilLog model = new OilLog();
		for (int i=0; i<FIELDS.length; i++) {
			int columnIndex = cursor.getColumnIndex(FIELDS[i]);
			model.maps.put(FIELDS[i], cursor.getString(columnIndex));
		}
		return model;
	}
	
	
	
	

}
